<?php


namespace App\Models;


use App\Engine\BaseModel;

class Live extends BaseModel
{
    protected $table = 'lives';
    protected $fillable = [
        'name',
        'cover_img',
        'start_time',
        'end_time',
        'anchor_name',
        'roomid',
        'goods',
        'live_status',
        'share_img',
        'live_type',
        'close_like',
        'close_goods',
        'close_comment',
        'close_kf',
        'close_replay',
        'is_feeds_public',
        'creater_openid',
        'feeds_img',
        'play_back_url',
    ];
    public function user()
    {
        return $this->belongsTo("App\Models\User","creater_openid","openid")->select(["id","nickname","avatar","openid"]);
    }

    public function getStartTimeAttribute($value)
    {
        return date("m-d H:i:s",$value);
    }


    public function setPlayBackUrlAttribute($value)
    {
        $this->attributes["play_back_url"]=json_encode($value,256);
    }

    public function getPlayBackUrlAttribute($value)
    {
        return $value!=''?json_decode($value,256):[];
    }

    public function setGoodsAttribute($value)
    {
        $this->attributes["goods"]=$value!=''?json_encode($value,256):json_encode([],256);

    }

    public function getGoodsAttribute($value)
    {
        return $value!=''?json_decode($value,256):[];
    }
}
